package interceptor

import (
	"context"
	"fmt"

	"gitee.com/krio/helper/logger"
	"google.golang.org/grpc"
)

func GrpcRecover(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
	defer func() {
		if err := recover(); err != nil {
			logger.WithContext(ctx).Errorf("panic: %v\n", err)
			err = fmt.Errorf("panic: %v", err) // TODO 需要研究下
		}
	}()

	resp, err := handler(ctx, req)
	return resp, err

}
